package com.zc.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zc.dto.ExamScoreTrendDTO;
import com.zc.dto.ScoreStudentDTO;
import com.zc.mapper.ScoresMapper;
import com.zc.pojo.Scores;
import com.zc.service.ScoresService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class ScoresServiceImpl extends ServiceImpl<ScoresMapper, Scores> implements ScoresService {
    @Resource
    private ScoresMapper scoresMapper;

    // 分页查询成绩，关联学生信息
    public IPage<ScoreStudentDTO> selectScoreWithStudent(Page<ScoreStudentDTO> page,
                                                         String name,
                                                         Integer examId,
                                                         String selectedClass) {
        return scoresMapper.selectScoreWithStudent(page, name, examId, selectedClass);
    }

    // 场景1：导出选中的学生数据（根据studentId列表）
    public List<ScoreStudentDTO> exportSelectedStudents(List<Integer> studentIds) {
        return scoresMapper.selectByStudentIds(studentIds);
    }

    // 场景2：按筛选条件导出：查询符合条件的所有成绩+学生数据（不分页）
    @Override
    public List<ScoreStudentDTO> exportScoreWithStudent(String name, Integer examId, String selectedClass) {
        return scoresMapper.exportScoreWithStudent(name, examId, selectedClass);
    }

    @Override
    public boolean exists(Integer studentId, Integer examId) {
        LambdaQueryWrapper<Scores> lqw = new LambdaQueryWrapper<>();
        lqw.eq(Scores::getStudentId, studentId)
                .eq(Scores::getExamId, examId);
        return baseMapper.exists(lqw);
    }

    @Override
    public List<ExamScoreTrendDTO> getStudentScoreTrend(Integer studentId) {
        // 调用Mapper获取学生的成绩趋势数据
        return scoresMapper.selectStudentScoreTrend(studentId);
    }
}

